<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title>修改密码</title>
  <link rel="stylesheet" href="${path}/statics/layui/css/layui.css">
</head>
<body>
 
  <form class="layui-form" action="" style = "padding : 10px;">

  <div class="layui-form-item">
    <label class="layui-form-label">当前密码</label>
    <div class="layui-input-block">
      <input type="text" name="currPwd" id="currPwdId" lay-verify="required|checkPwd"  placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">新密码</label>
    <div class="layui-input-block">
      <input type="text" name="newPwd" id="newPwdId"  lay-verify="required|checkNewPwd"  placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">确认密码</label>
    <div class="layui-input-block">
      <input type="text" name="confirmPwd" id="confirmPwdId"  lay-verify="required|checkConfirmPwd"  placeholder="请输入" autocomplete="off" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button type="submit" class="layui-btn" name="submit" id="saveBtnID" lay-submit lay-filter="saveBtn">保存</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
 
<script src="${path}/statics/layui/layui.js"></script> 
<script>
//Demo
layui.use(['form','layer','jquery'], function(){
  var layer = layui.layer;
  var form = layui.form;
  var $ = layui.jquery;
 
  
  //layUI表单验证
	  form.verify({
		  //验证当前密码是否正确
		  checkPwd: function(value,item){
			  var isTrue = false;
			 $.ajax({
				 url: "${path}/loginCtl/checkPwd",
				 data: {currPwd:value},
				 type: "post",
				 async:false,
				 success: function(res){
					 console.log(res)
					 if(res == 0){
						 isTrue = true;
					 }
				 }
			 })
			 if(isTrue){
				 return "当前密码不正确!";
			 }
		  },
	      
	  	  checkNewPwd: function(value,item){
	  		  if(value == $("#currPwdId").val()){
	  			  return "和旧密码一样了!"
	  		  }
	  	  },
	  	  
		  checkConfirmPwd: function(value,item){
		  		  if(value != $("#newPwdId").val()){
		  			  return "确认密码出错!"
		  		  }
		  }
	  });
  	  
  
  
	  //监听提交
	  form.on('submit(saveBtn)', function(data){
	    //layer.msg(JSON.stringify(data.field));
	    $.post("${path}/loginCtl/updatePwd",{newPwd:$("#newPwdId").val()},function(res){
	    	if(res == 0){
	    		layer.msg("修改成功,即将跳转到登录页面",{icon:1},function(){
		    		//在内联框架中的子级页面关闭父级页面弹出框
			      	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
		          	parent.layer.close(index); //再执行关闭   
		          	location.replace("${path}/loginCtl/logOut");
		    	 });
	    	}else{
	    		layer.msg("操作失败",{icon:2});
	    	}
	    })
	    
	    return false;
	  });
});
</script>
 
</body>
</html>